import request from '@/utils/request';
import { dayjs } from 'element-plus';

// 查询订单列表
export function listOrder(query) {
  return request({
    url: '/system/order/list',
    method: 'get',
    params: {
      orderType: 1,
      ...query
    }
  });
}

// 查询投诉列表
export function listComplaint(query) {
  return request({
    url: '/system/order/list',
    method: 'get',
    params: {
      cTopType: '2,5,6',
      cTopStatus: 1,
      typeCode: 1,
      ...query
    }
  });
}

// 查询订单详情
export function getOrder(orderId) {
  return request({
    url: '/system/order/' + orderId,
    method: 'get'
  });
}

// 新增订单
export function addOrder(data) {
  return request({
    url: '/system/order',
    method: 'post',
    data: data
  });
}

// 修改订单
export function updateOrder(data) {
  return request({
    url: '/system/order',
    method: 'put',
    data: data
  });
}

// 删除订单
export function delOrder(orderId) {
  return request({
    url: '/system/order/' + orderId,
    method: 'delete'
  });
}

// 下发订单至业务员
export function assignOrderToSalesman(data) {
  return request({
    url: '/system/order/assign/salesman',
    method: 'post',
    data: data
  });
}

// 订单置顶
export function topOrder(data) {
  return request({
    url: '/system/order/top',
    method: 'post',
    data: data
  });
}

// 订单物流发货
export function logisticsShipping(data) {
  return request({
    url: '/system/order/logistics/shipping',
    method: 'post',
    data: data
  });
}

// 订单物流取消
export function logisticsCancel(data) {
  return request({
    url: '/system/order/logistics/cancel',
    method: 'post',
    data: data
  });
}

// 订单取消
export function cancelOrderX(data) {
  return request({
    url: '/system/order/cancel',
    method: 'post',
    data: data
  });
}

// 订单核销
export function verificationOrder(data) {
  return request({
    url: '/system/order/verification',
    method: 'post',
    data: data
  });
}

// 订单完成
export function completeOrderStatus(data) {
  return request({
    url: '/system/order/complete',
    method: 'post',
    data: data
  });
}

// 查询待分配订单
export function listNotAssignedOrders(query) {
  return request({
    url: '/system/order/not/assigned/list',
    method: 'get',
    params: query
  });
}

// 查询公海订单
export function listHighSeasOrders(query) {
  return request({
    url: '/system/order/highSeas/list',
    method: 'get',
    params: query
  });
}

// 查询今天起未分配的新订单
export function listNotAssignedComplaintOrders() {
  return request({
    url: '/system/order/list',
    method: 'get',
    params: {
      orderType: 1, // 平台订单
      pageSize: 200,
      pageNum: 1,
      assignStatus: 1, // 未分配
      params: {
        beginOrderTime: dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
        endOrderTime: dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')
      }
    }
  });
}
